from langchain_community.llms.tongyi import Tongyi
from langchain_core.prompts import PromptTemplate, HumanMessagePromptTemplate, AIMessagePromptTemplate, \
    ChatPromptTemplate
1
# 基础提问-回答模板
# template = "帮我返回{res}中答案"
# prompt_template = PromptTemplate.from_template(template)
# prompt = prompt_template.format(res="1+1")
# llm = Tongyi()
# res = llm.invoke(prompt)
# print(res)
2
# ChatPromptTemplate案例
# human_template = "我喜欢{season}，帮我写一篇200字的文章"
# prompt_human_template = HumanMessagePromptTemplate.from_template(human_template)
#
# ai_template = "你是一个作家，擅长写作"
# prompt_ai_template = AIMessagePromptTemplate.from_template(ai_template)
#
# prompt_chat = ChatPromptTemplate.from_messages(
#     [prompt_human_template, prompt_ai_template]
# )
# format_prompt = prompt_chat.format_prompt(season="春天").to_messages()
#
# llm = Tongyi()
# res = llm.invoke(format_prompt)
# print(res)
3
